using System.Web.Mvc;

namespace KlearStorage // TODO: Shouldn't be this!?!
{
    public static class ModelStateValidationExtensions
    {
        public static bool Validate(this UniversalEntity entity, ModelStateDictionary ModelState)
        {
            return entity.Validate(new ModelStateValidationDictionary(ModelState));
        }
    }

    public class ModelStateValidationDictionary : IValidationDictionary
    {
        private readonly ModelStateDictionary _modelState;

        public ModelStateValidationDictionary(ModelStateDictionary modelState)
        {
            _modelState = modelState;
        }

        public void AddModelError(string key, string errorMessage)
        {
            _modelState.AddModelError(key, errorMessage);
        }

        public bool IsValid
        {
            get { return _modelState.IsValid; }
        }
    }
}